import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author caiwl
 * @date 2020/8/24 17:54
 */
public class TimerMain {
    public static void main(String[] args) {
        Timer timer = new Timer("Test Timer");
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                System.out.println("main task run");
                TimerTask nextTask = new TimerTask() {
                    @Override
                    public void run() {
                        System.out.println("next task run");
                    }
                };
                Date nextTime = new Date(System.currentTimeMillis() + 10000L);
                timer.schedule(nextTask, nextTime);
            }
        };
        Date time = new Date(System.currentTimeMillis() + 3000L);
        timer.schedule(task, time);

//        timer.cancel();
    }
}
